Skip to main content

ModulesOnRails

ModulesOnRails is a module import creation tool that allows for easy access to any module in your codebase. It replaces the need for require() and long paths reference by offering an alternative in the form of Import(). Import is a function1 generated by ModulesOnRails that takes a string and requires the module with a matching name within your codebase. Import understands runcontext so if you call it when in a client runcontext, it will only be able to see modules under your Client, Shared, and node_modules sections. Attempting to Import something that the Importer does not have access to or cannot find will result in an error.

Yielding in the global scope

All modules you write within Orion should have no yields on the global scope, any yields will result in an error from MoR.

Usage

In order to access the importer you can use the following code within any module in an Orion based codebase:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Import = require(ReplicatedStorage.Orion.Import)
tip

This codeblock can be easily generated with the preamble snippet provided with Orion.

Accessing the Import module is the only time you should ever have to declare an explicit path to a module. Once you have access to the Importer you can import any module by just providing the name of the module as a string like so:

local Promise = Import("Promise")
local Janitor = Import("Janitor")
tip

You can quickly generate imports similar to the above by using the import snippet provided with Orion.

Currently ModulesOnRails does not support modules sharing names within the same context as the practice can lead to obscurity on which module is actually being imported. On the flipside this allows for our plugin to be able to properly infer the module's contents and provide linting for its usage. As a result of having everything have unique names, Import can be utilized outside of the standard Orion execution model.

Although not recommended, the Import module does support using it as a table such that Import("Promise") and Import.Promise are equivalent.


  1. The Import Module is actually a table with a __call metamethod that allows for usage as a function.